package users

import (
	v1 "ginx/api/users/v1"
	"ginx/internal/global/configs"
	"ginx/internal/utils"
)

func (u *Users) GetTotpUrl(req *v1.OtpUrlReq) (res *v1.OtpUrlRes, secret string, err error) {

	otpkey, err := utils.OTP.GenerateOTPKey(configs.C.Server.Name, req.Email)
	if err != nil {
		return nil, "", err
	}

	// 生成OTP二维码的URL
	otpurl := otpkey.URL()

	res = &v1.OtpUrlRes{
		Url: otpurl,
	}
	return res, otpkey.Secret(), nil
}
